package org.example.shiro.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.realm.AuthenticatingRealm;
import org.apache.shiro.util.ByteSource;

/**
 * @author sky
 * @date 2025年03月25日 15:34
 * @description
 */
public class CustomerRealm1 extends AuthenticatingRealm{
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        // 获取token中的用户名
        String principal = (String) authenticationToken.getPrincipal().toString();
        System.out.println("用户名:" + principal);
        // 假设这是从数据库中查询到的信息
        String username = "zhangsan";
        String password = "1234";
        // 根据用户名查询数据库
        if (username.equals(principal)){
            //参数1:数据库用户名
            //参数2:数据库md5+salt之后的密码
            //参数3:注册时的随机盐
            //参数4:realm的名字
            SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(principal,password, null,this.getName());

            return simpleAuthenticationInfo;
        }
        return null;
    }
}
